﻿using System.Web.Routing;
using Orchard.Environment;
using Orchard.Localization;
using Orchard.UI.Navigation;

namespace PmpNetwork
{
    public class AdminMenu : INavigationProvider
    {
        private readonly Work<RequestContext> _requestContextAccessor;
        public string MenuName
        {
            get { return "admin"; }
        }

        public AdminMenu(Work<RequestContext> requestContextAccessor)
        {
            _requestContextAccessor = requestContextAccessor;
            T = NullLocalizer.Instance;
        }

        private Localizer T { get; set; }

        public void GetNavigation(NavigationBuilder builder)
        {
            var requestContext = _requestContextAccessor.Value;
            var idValue = (string)requestContext.RouteData.Values["id"];
            var id = 0;

            if (!string.IsNullOrEmpty(idValue))
            {
                int.TryParse(idValue, out id);
            }

            builder

                // Image set
                .AddImageSet("pmpnetwork")

                // "PmpNetwork"
                .Add(item => item

                    .Caption(T("PmpNetwork"))
                    .Position("2")
                    .LinkToFirstChild(true)

                    // "Wiki"
                    .Add(subItem => subItem
                        .Caption(T("Wiki"))
                        .Position("2.1")
                        .Action("Index", "WikiAdmin", new { area = "PmpNetwork" })
                        .Add(T("Details"), i => i.Action("Edit", "WikiAdmin", new { id }).LocalNav())
                        .Add(T("Questions"), i => i.Action("Questions", "WikiAdmin", new { id }).LocalNav())
                    )

                    // "Test"
                    //.Add(subItem => subItem
                    //    .Caption(T("Test"))
                    //    .Position("2.2")
                    //    .Action("Index", "WikiAdmin", new { area = "PmpNetwork" })
                    //)
                );
        }
    }
}